using System.Text;
using Unity.Profiling;
using UnityEngine;
 
public class RenderStatsScript : MonoBehaviour
{
    string statsText;
    ProfilerRecorder setPassCallsRecorder;
    ProfilerRecorder drawCallsRecorder;
    ProfilerRecorder verticesRecorder;
    ProfilerRecorder trianglesRecorder;
    ProfilerRecorder DyBatTimeRecorder;
//5404 1862
//5410 1864
    void OnEnable()
    {//Triangles Count Dynamic Batching Time
        setPassCallsRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Render, "SetPass Calls Count");
        drawCallsRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Render, "Draw Calls Count");
        verticesRecorder = ProfilerRecorder.StartNew(ProfilerCategory.Render, "Vertices Count");
        trianglesRecorder=ProfilerRecorder.StartNew(ProfilerCategory.Render, "Triangles Count");
        DyBatTimeRecorder=ProfilerRecorder.StartNew(ProfilerCategory.Render, "Dynamic Batching Time");
    }
 
    void OnDisable()
    {
        setPassCallsRecorder.Dispose();
        drawCallsRecorder.Dispose();
        verticesRecorder.Dispose();
    }

    void Update()
    {
        var sb = new StringBuilder(500);
        if (setPassCallsRecorder.Valid)
            sb.AppendLine($"SetPass Calls: {setPassCallsRecorder.LastValue}");
        if (drawCallsRecorder.Valid)
            sb.AppendLine($"Draw Calls: {drawCallsRecorder.LastValue}");
        if (verticesRecorder.Valid)
            sb.AppendLine($"Vertices: {verticesRecorder.LastValue}");
        if(trianglesRecorder.Valid)
            sb.AppendLine($"Triangles: {trianglesRecorder.LastValue}");
        if(DyBatTimeRecorder.Valid)
            sb.AppendLine($"DyBatTime: {DyBatTimeRecorder.LastValue}");
        statsText = sb.ToString();
    }
 
    void OnGUI()
    {
        GUIStyle style = new GUIStyle
        {
            border = new RectOffset(10, 10, 10, 10),
            fontSize = 20,
            fontStyle = FontStyle.BoldAndItalic,            
        };//Label
        GUI.Label(new Rect(10, 60, 500, 200), statsText,style);
    }
}
